def is_valid_id(user_id):
    if len(user_id) > 8:
        return False
    for char in user_id:
        if not (char.isdigit() or char.isalpha() or char == '_'):
            return False
    return True

def is_valid_email(email):
    if '@' not in email or '.' not in email:
        return False
    local, domain = email.split('@')
    if not local or not domain or '.' not in domain:
        return False
    return True

def is_valid_id_card(id_card):
    if len(id_card) != 18:
        return False
    if not id_card[:-1].isdigit():
        return False
    if not (id_card[-1].isdigit() or id_card[-1] == 'X'):
        return False
    return True

def is_valid_name(name):
    if len(name) > 4:
        return False
    for char in name:
        if not '\u4e00' <= char <= '\u9fff':
            return False
    return True

def get_gender_from_id_card(id_card):
    gender_digit = int(id_card[16])
    return '男' if gender_digit % 2 == 1 else '女'

def main():
    user_id = input("请输入ID（长度不超过8位，且只能由数字、字母、下划线组成）：")
    while not is_valid_id(user_id):
        print("ID格式不正确，请重新输入。")
        user_id = input("请输入ID（长度不超过8位，且只能由数字、字母、下划线组成）：")

    email = input("请输入EMAIL地址：")
    while not is_valid_email(email):
        print("EMAIL格式不正确，请重新输入。")
        email = input("请输入EMAIL地址：")

    id_card = input("请输入身份证号：")
    while not is_valid_id_card(id_card):
        print("身份证号格式不正确，请重新输入。")
        id_card = input("请输入身份证号：")

    name = input("请输入姓名（只能中文且不能超过4位）：")
    while not is_valid_name(name):
        print("姓名格式不正确，请重新输入。")
        name = input("请输入姓名（只能中文且不能超过4位）：")

    gender = get_gender_from_id_card(id_card)
    print("\n用户注册信息如下：")
    print("ID: {}".format(user_id))
    print("EMAIL地址: {}".format(email))
    print("身份证号: {}".format(id_card))
    print("姓名: {}".format(name))
    print("性别: {}".format(gender))

if __name__ == "__main__":
    main()